/**
 * @Date 2025/1/7 9:22
 * @Created by 衡盛永
 */

package org.example.deploy.controller;

import org.example.deploy.dto.ResultDto;
import org.example.deploy.pojo.SysMenu;
import org.example.deploy.service.SysMenuService;
import org.example.deploy.vo.menu.AssignMenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/menu")
public class MenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("aside_list")
    public ResultDto<List<SysMenu>> getAsideMenuList() {
        List<SysMenu> treeMenus = sysMenuService.getMenusByUserId();
        return ResultDto.success("获取菜单成功", treeMenus);
    }

    @GetMapping("list")
    public ResultDto<List<SysMenu>> getAllMenuList() {
        List<SysMenu> treeMenus = sysMenuService.getAllMenus();
        return ResultDto.success("获取菜单列表成功", treeMenus);
    }

    @PostMapping("assign_menu")
    public ResultDto<Boolean> assignMenu(@RequestBody AssignMenuVo assignMenuVo) {
        Boolean b = sysMenuService.assignMenu(assignMenuVo.getRoleId(), assignMenuVo.getMenuIds());
        return ResultDto.success("分配菜单成功", true);
    }
}
